package com.qding.park.manager.rest.controller.wx;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qding.park.common.core.exceptions.BaseException;
import com.qding.park.common.core.exceptions.ExceptionMessage;
import com.qding.park.common.core.exceptions.business.validator.RchlValidatorException;
import com.qding.park.common.core.exceptions.system.SystemUnKnown;
import com.qding.park.common.core.validate.RchlValidateBean;
import com.qding.park.common.core.validate.RchlValidateTools;
import com.qding.park.manager.common.pojo.ParkDataResult;
import com.qding.park.manager.common.rest.domain.AnswerMsg;
import com.qding.park.manager.common.rest.domain.AnswerMsgFactoryImpl;
import com.qding.park.manager.common.rest.enums.ResponseCodeEnum;
import com.qding.park.manager.facade.core.service.common.HisCommonFacade;
import com.qding.park.manager.rest.controller.WebBaseController;

/**
  * @ClassName: WX_History_Controller
  * @Description: 历史记录
  * @author Comsys-Administrator
  * @date 2016年10月18日 上午11:03:41
  *
  */
@RestController
public class WX_History_Controller extends WebBaseController{
	
	private static final Log _log = LogFactory.getLog(WX_History_Controller.class);
	
	@Autowired
	private HisCommonFacade   hisCommonFacade;
	
	
	@RequestMapping("/wx/historyRecord/paymentRecordList")
	public AnswerMsg paymentRecordList(String phone, String userId,String jumpPage,String pageLength) {
			
		try {
			/******验证字段********/
			RchlValidateBean vb = new RchlValidateBean();
			vb.getPhoneValidate().put("phone", phone);
			vb.getRequiredValidate().put("userId", userId);
			vb.getRequiredValidate().put("jumpPage", jumpPage);
			vb.getRequiredValidate().put("pageLength", pageLength);
			
			vb.getIntValidate().put("jumpPage", jumpPage);
			vb.getIntValidate().put("pageLength", pageLength);
			vb.getLongValidate().put("phone", phone);
			RchlValidateTools.validate(vb);
			/**************/
			
			int jumpPageint=Integer.valueOf(jumpPage);
			int pageLengthint=Integer.valueOf(pageLength);
			ParkDataResult parkDataResult = hisCommonFacade.paymentRecordList_rest_wx(Long.valueOf(phone),userId,jumpPageint,pageLengthint);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(parkDataResult.getData());
			return answerMsg;
		}catch(RchlValidatorException e){
//			e.getExceptionMessage().appendDetailText("CarController.myCars:"+"userId="+userId+",phone"+phone);
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.VALIDATION_ERROR.getValue(),
					e.getExceptionMessage().getSimpleText()+";"+e.getExceptionMessage().getDetailText());
			return answerMsg;
		}catch(BaseException e){
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.BUSINESS_ERROR.getValue(),
					e.getExceptionMessage().getName()+e.getExceptionMessage().getSimpleText());
			return answerMsg;
		}catch (Exception e) {
			SystemUnKnown ex=new SystemUnKnown(e,
					ExceptionMessage.createExceptionMessage(SystemUnKnown.default_Name,
														"未知Exception", "userId="+userId+",phone="+phone));
			exceptionHandle.handle(ex);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.SYSTEM_ERROR);
			return answerMsg;
		}
	}
	
	
	@RequestMapping("/wx/historyRecord/paymentRecordInfo")
	public AnswerMsg paymentRecordInfo(String recordId) {
			
		try {
			/******验证字段********/
			RchlValidateBean vb = new RchlValidateBean();
			vb.getRequiredValidate().put("recordId", recordId);
			
			RchlValidateTools.validate(vb);
			/**************/
			
			ParkDataResult parkDataResult = hisCommonFacade.paymentRecordInfo_rest_wx(recordId);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(parkDataResult.getData());
			return answerMsg;
		}catch(RchlValidatorException e){
//			e.getExceptionMessage().appendDetailText("CarController.myCars:"+"userId="+userId+",phone"+phone);
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.VALIDATION_ERROR.getValue(),
					e.getExceptionMessage().getSimpleText()+";"+e.getExceptionMessage().getDetailText());
			return answerMsg;
		}catch(BaseException e){
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.BUSINESS_ERROR.getValue(),
					e.getExceptionMessage().getName()+e.getExceptionMessage().getSimpleText());
			return answerMsg;
		}catch (Exception e) {
			SystemUnKnown ex=new SystemUnKnown(e,
					ExceptionMessage.createExceptionMessage(SystemUnKnown.default_Name,
														"未知Exception", "recordId="+recordId));
			exceptionHandle.handle(ex);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.SYSTEM_ERROR);
			return answerMsg;
		}
	}
	
	@RequestMapping("/wx/historyRecord/paymentRecordDel")
	public AnswerMsg paymentRecordDel(String recordId) {
			
		try {
			/******验证字段********/
			RchlValidateBean vb = new RchlValidateBean();
			vb.getRequiredValidate().put("recordId", recordId);
			
			RchlValidateTools.validate(vb);
			/**************/
			
			ParkDataResult parkDataResult = hisCommonFacade.paymentRecordDel_rest_wx(recordId);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(parkDataResult.getData());
			return answerMsg;
		}catch(RchlValidatorException e){
//			e.getExceptionMessage().appendDetailText("CarController.myCars:"+"userId="+userId+",phone"+phone);
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.VALIDATION_ERROR.getValue(),
					e.getExceptionMessage().getSimpleText()+";"+e.getExceptionMessage().getDetailText());
			return answerMsg;
		}catch(BaseException e){
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.BUSINESS_ERROR.getValue(),
					e.getExceptionMessage().getName()+e.getExceptionMessage().getSimpleText());
			return answerMsg;
		}catch (Exception e) {
			SystemUnKnown ex=new SystemUnKnown(e,
					ExceptionMessage.createExceptionMessage(SystemUnKnown.default_Name,
														"未知Exception", "recordId="+recordId));
			exceptionHandle.handle(ex);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.SYSTEM_ERROR);
			return answerMsg;
		}
	}
}
